﻿using ProjBackEnd.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;

namespace ProjBackEnd.Areas.Sys.Models
{
    #region 用户登录

    /// <summary>
    /// 用户登录结果集
    /// </summary>
    public class ResultUserLoginInfo : BaseResultInfo
    {
        /// <summary>
        /// 用户名称
        /// </summary>
        public string username { get; set; }
        /// <summary>
        /// 用户系统id
        /// </summary>
        public string memberid { get; set; }
        /// <summary>
        /// 用户头像url
        /// </summary>
        public string avatar { get; set; }
        /// <summary>
        /// 手机号
        /// </summary>
        public string mpno { get; set; }
        /// <summary>
        /// 身份令牌
        /// </summary>
        public string token { get; set; }
        /// <summary>
        /// 归属部门编码
        /// </summary>
        public string deptcd { get; set; }
        /// <summary>
        /// 权限菜单列表
        /// </summary>
        public List<Menuinfo> menuinfo { get; set; } = new List<Menuinfo>();
    }

    public class ResultUserMenuInfo : BaseResultInfo
    {
        /// <summary>
        /// 权限菜单列表
        /// </summary>
        public List<Menuinfo> menuinfo { get; set; }
    }

    public class MenuPagesInfo
    {
        public int pageid { get; set; }
        public string pagecd { get; set; }
        public string pagenmchg { get; set; }
        public string pagenmeng { get; set; }
        public int pageorder { get; set; }
    }

    /// <summary>
    /// 权限菜单列表
    /// </summary>
    public class Menuinfo
    {
        /// <summary>
        /// 菜单id
        /// </summary>
        public int menuid { get; set; }
        /// <summary>
        /// 父级菜单id
        /// </summary>
        public int pmenuid { get; set; }
        /// <summary>
        /// 菜单代码
        /// </summary>
        public string menucd { get; set; }
        /// <summary>
        /// 菜单中文名
        /// </summary>
        public string menunmchg { get; set; }
        /// <summary>
        /// 菜单英文名
        /// </summary>
        public string menunmeng { get; set; }
        /// <summary>
        /// 挂载的窗体名称
        /// </summary>
        public string formnm { get; set; }
        /// <summary>
        /// 序号
        /// </summary>
        public int menuorder { get; set; }
        /// <summary>
        /// 窗体打开方式
        /// </summary>
        public string opentp { get; set; }
        /// <summary>
        /// 图标链接
        /// </summary>
        public string iconurl { get; set; }
    }

    /// <summary>
    /// 用户登录请求
    /// </summary>
    public class ReqUserLoginInfo
    {
        /// <summary>
        /// 用户登录名（手机号或用户id）
        /// </summary>
        [StringLength(30, ErrorMessage = "用户名无效")]
        public string loginid { get; set; }

        /// <summary>
        /// 密码
        /// </summary>
        [Required(ErrorMessage = "必须输入密码")]
        [StringLength(100, ErrorMessage = "用户密码超限")]
        public string password { get; set; }
        /// <summary>
        /// 公司代码
        /// </summary>
        [Required(ErrorMessage = "公司代码是必需的")]
        [StringLength(4, ErrorMessage = "公司代码非法")]
        public string comcd { get; set; }
        /// <summary>
        /// 登录方式（A-自动登录；B-手动登录）
        /// </summary>
        [Required(ErrorMessage = "登录方式是必需的")]
        public string logintp { get; set; }
        /// <summary>
        /// 登录平台代码
        /// </summary>
        [Required(ErrorMessage = "平台代码是必需的")]
        public string platcd { get; set; }
    }

    #endregion

    #region 用户管理

    public class ReqUserInfo : BaseUserRequest
    {
        /// <summary>
        /// 要操作的用户对象
        /// </summary>
        public UserInfo_Modify userinfo { get; set; }
    }

    /// <summary>
    /// 自助修改密码请求
    /// </summary>
    public class ReqSelfChangePwd : BaseUserRequest
    {
        /// <summary>
        /// 原始登录密码
        /// </summary>
        [Required(ErrorMessage = "原始登录密码是必需的")]
        public string originpwd { get; set; }

        /// <summary>
        /// 新登录密码
        /// </summary>
        [Required(ErrorMessage = "新登录密码是必需的")]
        public string newpwd { get; set; }

        /// <summary>
        /// 确认新密码
        /// </summary>
        [Compare("NewPassword", ErrorMessage = "新密码和确认密码不匹配。")]
        public string ConfirmPassword { get; set; }
    }

    public class ResultUsers : BaseResultInfo
    {
        /// <summary>
        /// 员工信息列表
        /// </summary>
        public List<ComUserInfo> userlist { get; set; }
    }

    /// <summary>
    /// 用户常规信息
    /// </summary>
    public class UserInfo : BaseOperableEntity
    {
        /// <summary>
        /// 用户系统id（仅内部交互）
        /// </summary>
        [RequiredConditional("optlb", "U", ErrorMessage = "用户系统id是必需的")]
        [RequiredConditional("optlb", "D", ErrorMessage = "用户系统id是必需的")]
        public string memberid { get; set; }
        /// <summary>
        /// 用户id（可用于登录）
        /// </summary>
        public string userid { get; set; }
        /// <summary>
        /// 用户姓名
        /// </summary>
        public string username { get; set; }
        /// <summary>
        /// 用户状态
        /// </summary>
        public string stat { get; set; }
        /// <summary>
        /// 手机号
        /// </summary>
        public virtual string mpno { get; set; }
    }

    /// <summary>
    /// 公司员工基本信息
    /// </summary>
    public class ComUserInfo : UserInfo
    {
        /// <summary>
        /// 公司代码
        /// </summary>
        public string comcd { get; set; }
        /// <summary>
        /// 公司名称
        /// </summary>
        public string comnm { get; set; }
        /// <summary>
        /// 部门代码
        /// </summary>
        public string deptcd { get; set; }
        /// <summary>
        /// 部门名称
        /// </summary>
        public string deptnm { get; set; }
    }

    /// <summary>
    /// 可操作的用户对象
    /// </summary>
    public class UserInfo_Modify : UserInfo
    {
        /// <summary>
        /// 手机号
        /// </summary>
        [RequiredConditional("optlb", "I", ErrorMessage = "手机号码是必需的")]
        public override string mpno { get; set; }

        /// <summary>
        /// 登录密码
        /// </summary>
        public virtual string password { get; set; }

        /// <summary>
        /// 头像url
        /// </summary>
        public string avatar { get; set; }

        /// <summary>
        /// 用户昵称
        /// </summary>
        public string nickname { get; set; }

        /// <summary>
        /// 用户所属部门
        /// </summary>
        public string deptcd { get; set; }
    }


    public class RegUserInfo_SelfReg : UserInfo_Modify
    {
        [Required(ErrorMessage = "密码是必需的")]
        public override string password { get; set; }
    }

    /// <summary>
    /// 登录成功后返回的用户对象
    /// </summary>
    public class UserInfo_LoginSucc:UserInfo
    {
        /// <summary>
        /// 头像url
        /// </summary>
        public string avatar { get; set; }
        /// <summary>
        /// 归属部门编码
        /// </summary>
        public string deptcd { get; set; }
    }

    #endregion
}